/************************************************************************************************
*Analizador lexico para c--                                                                     *
*Author     :   Simon Emmanuel Gutierrez Brida                                                  *
*Version    :   0.2                                                                             *
*Fecha      :   Octubre/2011                                                                    *
*----------------------------------------------------                                           *
*-Analiza la sintaxis del codigo                                                                *
*-Almacena los valores de los tokens (aquellos que son utiles)                                  *
*************************************************************************************************/


%{
#include "utils/variable.h"
#include <stdlib.h>
#include "y.tab.h"
#include  <stdio.h>
//extern int yylval;
int lineCount = 1;
int charCount = 1;

%}

intw        "int"
floatw      "float"
if          "if"
continue    "continue"
else        "else"
return      "return"
break       "break"
while       "while"
letter      [a-zA-Z]
pdigit      [1-9]
digit       [0-9]
dot         "."
int         0|({pdigit}{digit}*)
pint        ({pdigit}{digit}*)
plus        "+"
minus       "-"
mult        "*"
div         "/"
mod         "%"
admClose    "!"
questClose  "?"
twoPoints   ":"
equal       "="
dequal      "=="
comma       ","
oangle      "<"
cangle      ">"
oparen      "("
cparen      ")"
oparen2     "{"
cparen2     "}"
or          "||"
and         "&&"
dotcomma    ";"
exp         [Ee]
expVal      {exp}[+-]{pint}


%%
[ \t]+                                                          {/*ignore white spaces*/charCount += 1;};
{break}                                                         {charCount += strlen(yylval.stringVal); return(BREAK);}
{if}                                                            {charCount += strlen(yylval.stringVal); return(IF);}
{continue}                                                      {charCount += strlen(yylval.stringVal); return(CONTINUE);}
{intw}                                                          {yylval.stringVal = strdup(yytext); charCount += strlen(yylval.stringVal); return(INTW);}
{else}                                                          {charCount += strlen(yylval.stringVal); return(ELSE);}
{return}                                                        {charCount += strlen(yylval.stringVal); return(RETURN);}
{floatw}                                                        {yylval.stringVal = strdup(yytext); charCount += strlen(yylval.stringVal); return(FLOATW);}
{while}                                                         {charCount += strlen(yylval.stringVal); return(WHILE);}
{int}                                                           {yylval.intVal = atoi(yytext); charCount += strlen(yytext); return(INTEGER); }
({dot}{int}{expVal}?|{int}{dot}{int}?{expVal}?|{int}{expVal})   {yylval.floatVal = atof(yytext); charCount += strlen(yytext); return(FLOAT); }
{letter}({letter}|{digit})*                                     {yylval.stringVal = strdup(yytext); charCount += strlen(yylval.stringVal); return(ID); }
{plus}                                                          {charCount += strlen(yylval.stringVal); return(PLUS);}
{mult}                                                          {charCount += strlen(yylval.stringVal); return(MULT);}
{minus}                                                         {charCount += strlen(yylval.stringVal); return(MINUS);}
{div}                                                           {charCount += strlen(yylval.stringVal); return(DIV);}
{mod}                                                           {charCount += strlen(yylval.stringVal); return(MOD);}
{admClose}                                                      {charCount += strlen(yylval.stringVal); return('!');}
{questClose}                                                    {charCount += strlen(yylval.stringVal); return('?');}
{twoPoints}                                                     {charCount += strlen(yylval.stringVal); return(':');}
{equal}                                                         {charCount += strlen(yylval.stringVal); return(EQUAL);}
{dequal}                                                        {charCount += strlen(yylval.stringVal); return(DEQUAL);}
{comma}                                                         {charCount += strlen(yylval.stringVal); return(',');}
{oangle}                                                        {charCount += strlen(yylval.stringVal); return('<');}
{cangle}                                                        {charCount += strlen(yylval.stringVal); return('>');}
{oparen}                                                        {charCount += strlen(yylval.stringVal); return('(');}
{cparen}                                                        {charCount += strlen(yylval.stringVal); return(')');}
{oparen2}                                                       {charCount += strlen(yylval.stringVal); return('{');}
{cparen2}                                                       {charCount += strlen(yylval.stringVal); return('}');}
{or}                                                            {charCount += strlen(yylval.stringVal); return(OR);}
{and}                                                           {charCount += strlen(yylval.stringVal); return(AND);}
{dotcomma}                                                      {charCount += strlen(yylval.stringVal); return(';');}
"//".*\n                                                        {/*printf("Comment discarded : %s\n", yytext);*/lineCount++;charCount = 0;}
"/*".*"*/"                                                    {/*printf("Comment discarded : %s\n", yytext);*/ charCount += strlen(yylval.stringVal);}
\n                                                              {lineCount++;charCount = 0;}
.                                                               {/*printf("Incorrect simbol found : %s\n", yytext);*/return(ERROR);}
%%


